package com.own.business.wechat.official.controller;

import com.own.aop.login.LoginIgnore;
import com.own.business.wechat.official.entity.form.WechatShareSignForm;
import com.own.business.wechat.official.model.WechatSignModel;
import com.own.business.wechat.official.util.WechatOfficialUtil;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.component.log.operation.aop.LogOperationAop;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * WechatOfficialController
 *
 * @author chenxueli
 * @date 2023-09-25 17:32:26
 */
@Slf4j
@Tag(name = "微信公众号" + ConstantBeanSuffix.CONTROLLER)
@RestController
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + "wechat/official")
public class WechatOfficialController extends BaseController {

    @Resource
    private WechatOfficialUtil wechatOfficialUtil;

    @LoginIgnore
    @LogOperationAop
    @Operation(summary = "获取微信分享签名")
    @PostMapping(value = "/share/sign")
    public ResultModel<WechatSignModel> getShareSign(
            @RequestBody WechatShareSignForm form
    ) {
        form.check();
        // 获取ticket
        var model = wechatOfficialUtil.getShareSign(form.getUrl());
        return R.success(model);
    }

}
